﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                    mc:Ignorable="d" 
                    xmlns:mr="http://mishrareader.codeplex.com/Reader"
                    xmlns:reader="clr-namespace:MishraReader.ViewModels.Reader;assembly=MishraReader.ViewModels"
                    xmlns:mishraReader="clr-namespace:MishraReader;assembly=MishraReader.ViewModels">

    <DataTemplate DataType="{x:Type reader:ItemViewModel}" >
        <Grid>
            <mr:BusyIndicator IsBusy="{Binding IsBusy}" />

            <Grid x:Name="content">
               
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>


                <Grid>
                  
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Button Grid.ColumnSpan="2" Style="{StaticResource MetroCleanButton}" Margin="0,0,0,20" Cursor="Hand" Command="{Binding ViewInBrowserCommand}" d:LayoutOverrides="Height" >
                        <TextBlock x:Name="txtTitle" TextTrimming="CharacterEllipsis" ToolTip="{Binding Title}"  Style="{StaticResource MetroHeaderBold}" Text="{Binding Title}" />
                    </Button>

                    <Grid  Grid.Row="1"  Height="30" VerticalAlignment="Top">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <StackPanel Orientation="Horizontal" x:Name="panSubTitle" Margin="0,6,0,0"  >
                            <TextBlock DockPanel.Dock="Left" Text="{Binding Author}" Style="{DynamicResource MetroSmallBoldText}"  />
                            <TextBlock DockPanel.Dock="Left" Text=" - " Foreground="{DynamicResource MetroTextLightLight}"  Style="{DynamicResource MetroSmallBoldText}"/>
                            <TextBlock DockPanel.Dock="Left" Text="{Binding PublicationDate}" Style="{DynamicResource MetroSmallBoldText}" Foreground="{DynamicResource MetroTextLightLight}"/>
                        </StackPanel>


                        <StackPanel Grid.Column="1" Margin="0,0,0,5" Orientation="Horizontal" TextOptions.TextFormattingMode="Display">
                            <ToggleButton  x:Name="readButton"
                                Style="{StaticResource MetroCircleToggleButton}" Margin="0,0,10,0" IsChecked="{Binding Read}" 
                                ToolTip="{x:Static mishraReader:Strings.ToggleMarkAsRead}">


                                <Path Data="{StaticResource PathCheckmark}" x:Name="readStatus" Width="14" Height="14" Fill="{DynamicResource MetroLine}" Stretch="Fill" />


                            </ToggleButton>
                            <ToggleButton Style="{StaticResource MetroCircleToggleButton}" Margin="0,0,10,0" IsChecked="{Binding Starred}" 
                                ToolTip="{x:Static mishraReader:Strings.ToggleStarred}">
                                <Path x:Name="StarredPath" Data="M 0,0 l 10,0 l 5,-10 l 5,10 l 10,0 l -7,10 l 2,10 l -10,-5 l -10,5 l 2,-10 Z" Width="14" Height="14" Stretch="Fill" 
                            Fill="{DynamicResource MetroLine}" />

                            </ToggleButton>
                            <Button Style="{StaticResource MetroCircleButton}" Margin="0,0,10,0" Command="{Binding ShareCommand}" ToolTip="{x:Static mishraReader:Strings.Share}">
                                <Image Stretch="None" Source="/MishraReader;component/Assets/Light/Share.png" />
                            </Button>

                            <mr:ComboButton IsDropDownOpen="{Binding BookmarkViewModel.ShowData, Mode=TwoWay}"  
                                              Style="{DynamicResource ComboButtonCircleStyle}" 
                                              ArrowMargin="0,0,30,-1"
                                              ArrowHorizontalAlignment="Right"
                                              Margin="0,0,10,0" 
                                              VerticalOffset="0"
                                              HorizontalOffset="-393"
                                              ToolTip="{x:Static mishraReader:Strings.Bookmark}">
                                <mr:ComboButton.Header>
                                    <Image Stretch="None" Source="/MishraReader;component/Assets/Light/Bookmark.png"  />
                                </mr:ComboButton.Header>
                                <mr:ComboButton.Content>
                                    <ContentPresenter Content="{Binding BookmarkViewModel}" />
                                </mr:ComboButton.Content>
                            </mr:ComboButton>
                       
                            <Button 
                                
                            x:Name="btnOpenInBrowser"
                            Command="{Binding ViewInBrowserCommand}"
                            Style="{StaticResource MetroCircleButton}"
                            Margin="0"
                            ToolTip="{x:Static mishraReader:Strings.OpenInBrowser}">
                                <Image Stretch="None"
                                Source="/MishraReader;component/Assets/Light/Browse.png" />
                            </Button>

                            <!--<Popup AllowsTransparency="True" 
                            StaysOpen="False" 
                            IsOpen="{Binding BookmarkViewModel.ShowData, Mode=TwoWay}"
                            Placement="Left"  
                                   VerticalOffset="10"
                                   HorizontalOffset="40"
                            PlacementTarget="{Binding ElementName=btnBookmark}">

                                <ContentPresenter Content="{Binding BookmarkViewModel}" />
                            </Popup>-->
                            <mr:Dialog Content="{Binding ShareViewModel}" 
                                            Showing="{Binding ShareViewModel.ShowData}"
                                            CancelCommand="{Binding ShareViewModel.CancelCommand}"
                                            HorizontalContentAlignment="Right"
                                            Title="Not Used"/>

                        </StackPanel>



                        <Rectangle Height="1" Fill="{DynamicResource MetroScollbarBg}" VerticalAlignment="Bottom" Grid.ColumnSpan="2"  />
                    </Grid>
                   

                </Grid>

                <StackPanel Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,30,0,0">
                    <TextBlock Text="{x:Static mishraReader:Strings.PleaseWait}" Style="{DynamicResource MetroSmallText}"/>
                    <ProgressBar IsIndeterminate="True" Height="3"/>
                </StackPanel>

                <mr:HtmlViewer Grid.Row="1"  Margin="0,10,0,0" x:Name="browser" HtmlString="{Binding ItemData}" />

            </Grid>

        </Grid>

        <DataTemplate.Triggers>


            <DataTrigger Binding="{Binding Read}" Value="False">
                <Setter TargetName="readStatus" Property="Fill" Value="{DynamicResource MetroAccentBrush}"/>
            </DataTrigger>

            <DataTrigger Binding="{Binding Starred}" Value="True">
                <Setter TargetName="StarredPath" Property="Fill" Value="{DynamicResource MetroAccentBrush}"/>
                <Setter TargetName="readButton" Property="Visibility" Value="Collapsed" />
            </DataTrigger>
            
            <DataTrigger Binding="{Binding Item.IsReadStateLocked}" Value="True">
                <Setter Property="Visibility" TargetName="readButton" Value="Collapsed" />
            </DataTrigger>

            <DataTrigger Binding="{Binding ItemData, FallbackValue=1}" Value="{x:Null}">
                <Setter TargetName="content" Property="Visibility" Value="Collapsed" />
                <Setter TargetName="browser" Property="IsEnabled" Value="False" />
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
</ResourceDictionary>